package com.right.health.app.ui.common;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.magic.basic.activity.BaseActivity;
import com.right.health.app.R;
import com.right.health.app.dialog.MoreDialog;
import com.right.health.app.widget.ProgressWebView;

/*
 * Created by hopeliao on 2019-09-29
 *
 */
public class ArticleDetailActivity extends BaseActivity implements View.OnClickListener {
    private static final String EXTRA_TITLE = "title";
    private static final String EXTRA_URL = "url";

    private ProgressWebView mWebView;

    private TextView mTitleTv;

    private MoreDialog mMoreDialog;

    private String mTitle;

    @Override
    public void onCreate(Bundle bundle, String s) {
        setContentView(R.layout.artice_detail);
    }

    @Override
    public void findView() {
        mTitleTv = (TextView) findViewById(R.id.tv_title);

        findViewById(R.id.iv_more).setOnClickListener(this);

        mWebView = (ProgressWebView) findViewById(R.id.web_view);
    }

    @Override
    public void initialize() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            if (bundle.containsKey(EXTRA_TITLE)) {
                mTitleTv.setText(bundle.getString(EXTRA_TITLE));
            }
            if (bundle.containsKey(EXTRA_URL)) {
                mWebView.loadUrl(bundle.getString(EXTRA_URL));
            }
        }
    }

    public static void makeActivity(Activity act, String title, String url) {
        Intent intent = new Intent(act, ArticleDetailActivity.class);
        Bundle bundle = new Bundle();
        if (!TextUtils.isEmpty(title)) {
            bundle.putString(EXTRA_TITLE, title);
        }
        if (!TextUtils.isEmpty(url)) {
            bundle.putString(EXTRA_URL, url);
        }

        intent.putExtras(bundle);

        act.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_more:
                if (mMoreDialog == null) {
                    mMoreDialog = new MoreDialog(this);
                    mMoreDialog.setClickListener(this);
                }
                mMoreDialog.show();
                break;
            case R.id.tv_qrcode: //二维码
                break;
            case R.id.tv_copy: //复制
                break;
            case R.id.tv_refresh: //刷新
                break;
            case R.id.tv_browser: //浏览器打开
                break;
        }
    }


    private void dismiss() {
        if (mMoreDialog != null && mMoreDialog.isShowing()) {
            mMoreDialog.dismiss();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        dismiss();
    }
}
